package com.zhiwei.codesecurity.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class PageHelper {
    private static Logger logger = LoggerFactory.getLogger(PageHelper.class);

    public static final int count = 500;

    /**
     * 分页处理类
     * @param invoke
     * @param <T>
     */
    public static <T> void doInvoke(PageInvoke<T> invoke) {
        int limitIndex = 0;
        List<T> list = invoke.search(limitIndex);
        while (list != null && list.size() > 0) {
            for (T t : list) {
                try {
                    invoke.invoke(t);
                    limitIndex++;
                } catch (Exception e) {
                    limitIndex++;
                    logger.error("=====处理(obj={})失败!{}", t, e);
                }
            }
            list = invoke.search(limitIndex);
        }
    }
}
